package xp.ass.imitate.express.meta.node;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import xp.ass.imitate.express.impl.XExpressState;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chent3
 * @date 2024/9/4
 */
@Data
@NoArgsConstructor
public abstract class XTokenNode {

    // top 16 bit represent start pos, bottom 16 bit represent end pos
    private int pos;

    protected List<XTokenNode> childNodeList = new ArrayList<>();

    public XTokenNode(int pos) {
        this(pos, null);
    }

    public XTokenNode(int pos, List<XTokenNode> nodeList) {
        this.pos = pos;
        if (CollectionUtils.isNotEmpty(nodeList)) {
            this.childNodeList = nodeList;
        }
    }


    public int getStartPos() {
        return pos >> 16;
    }

    public int getEndPos() {
        return pos & 0xFFFF;
    }


    public abstract Object getValue(XExpressState state);
}
